package jedis.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import jedis.domain.province;
import jedis.service.ProvincesService;
import jedis.service.impl.ProvinceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/provinceServlet")
public class provinceServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProvincesService ps=new ProvinceServiceImpl();
        List<province> list = ps.findAll();
        ObjectMapper mapper=new ObjectMapper();
        String json = mapper.writeValueAsString(list);
        System.out.println(json);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
